#include "DoWhile.h"

DoWhile::DoWhile (NodeContainer* parent) : DiagramInline(parent) {  
  //loop condition
  terminals.push_back(new Terminal(this));
}


void DoWhile::process(llvm::IRBuilder<> *builder) {
  llvm::BasicBlock *preLoop = builder->GetInsertBlock();
  llvm::Function *TheFunction = preLoop->getParent();
  llvm::BasicBlock *loop = llvm::BasicBlock::Create(llvm::getGlobalContext(), "loop", TheFunction);
  builder->CreateBr(loop);
  llvm::BasicBlock::Create(llvm::getGlobalContext(), "postLoop", TheFunction);
  builder->SetInsertPoint(loop);
  int i=0;
  for (std::vector<ShiftRegister>::iterator it = shiftRegisters.begin();it!=shiftRegisters.end();++it, ++i) {
    std::string name("ShiftReg");
    name+=std::to_string(i);
    (*it).input->setValue(builder->CreatePHI(llvm::Type::getInt32Ty(llvm::getGlobalContext()),2,name));
  }

}
